package Servlets;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import QueryExcecution.NewPollQuestion;
import beanUtils.BeanUtility;
import beans.AddPollBean;

public class AddPoll extends HttpServlet{

	AddPollBean apb=new AddPollBean();
	NewPollQuestion npq=new NewPollQuestion();
	public void doGet(HttpServletRequest req, HttpServletResponse res)
			throws IOException, ServletException {
		try{
			doPost(req, res);
		}
		catch(Exception e){
			
		}
	}///do get///////
	public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
		System.out.println("hello add servlet called !!!  ");
		BeanUtility.populateBean(apb, req);
		
		String addPollQuestion=apb.getPollquestion();
		
		System.out.println("the question is ----->"+addPollQuestion);
		try {
		int success=npq.addNewPoll(addPollQuestion);
		RequestDispatcher requestDispatcher = req
				.getRequestDispatcher("./admin_index.jsp");
		requestDispatcher.forward(req, res);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}
}
